package com.shujia.wyh.day12;

import java.io.*;

/*
    使用字符流复制文件
    数据源：e.txt -- 字符输入流 -- Reader -- InputStreamReader
    目的地：f.txt -- 字符输出流 -- Writer -- OutputStreamWriter
 */
public class CopyFileDemo3 {
    public static void main(String[] args) throws IOException {
        //创建字符输入流对象
        InputStreamReader isr = new InputStreamReader(new FileInputStream("java/src/com/shujia/wyh/day12/e.txt"));

        //创建字符输入流对象
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("java/src/com/shujia/wyh/day12/f.txt"));

        //一次读写一个字符
//        int i = 0;
//        while ((i = isr.read()) != -1) {
//            osw.write(i);
//            osw.flush();
//        }

        //一次读写一个字符数组
        char[] chars = new char[1024];
        int length = 0;
        while ((length = isr.read(chars)) != -1) {
            osw.write(chars, 0, length);
            osw.flush();
        }

        //释放资源
        osw.close();
        isr.close();
    }
}
